<?php include dirname(__FILE__).'/common/header.php'; ?>

<?php include dirname(__FILE__).'/common/menu.php'; ?>

var attr = {};
attr.ctrlName = '<?php echo $ctrlName; ?>';
attr.game_gift = <?php echo $game_gift ?>;
attr.gift_status = [['0','未核销'],[1,'已核销']];
attr.type_arr = [[1,'儿时梦想篇'],[2,'焕然一新篇'],[3,'保护蓝天篇']];


var headers = [['customer_id','ID'],['openid','openid'],['h5_type','活动',function(val) {
                    try {
                        val = JSON.parse(val);
                        var arr = [];
                        Ext.each(val,function(el) {
                            arr.push(ZM.id2name(el,attr.type_arr));
                        });
                        return arr.join(',');
                    } catch(e) {
                        return '';
                    }
                    return ZM.id2name(val,attr.type_arr);
                }],
    ['gift_type','奖品',function(val,r) {
        if(val == 0) {
            return r.lottery_times > 0 ? '未中奖' : '未抽奖';
        }
        return ZM.id2name(val,attr.game_gift);
    }],['gift_status','奖品状态',function(val,r) {
        if(r.gift_type == 0) return '';
        return val == 1 ? '已核销' : '未核销';
    }],
    ['gift_code','卡券号'],['lottery_times','抽奖次数'],['customer_time_create','创建时间'],['customer_time_lottery','获奖时间'],
    ['customer_name','姓名'],['customer_car_number','车架号'],['create_source','初始化来源']];

/*
| -------------------------------------------------------------------
|  List Grid
| -------------------------------------------------------------------
*/
list.grid = new ZM.GridPanel({
    url: list.baseUrl + attr.ctrlName+'/getCustomerList',
    tbar:[{
        text:'导出过滤顾客',
        cls:'btn-show',
        hidden:!Ext.permission[attr.ctrlName + '/exportCustomerList'.toLowerCase()],
        handler:function() {
            var sortInfo = list.grid.store.getSortState();
            if(sortInfo) {
                list.grid.store.baseParams['sort'] = sortInfo['field'];
                list.grid.store.baseParams['dir'] = sortInfo['direction'];
            }
            exportExcel(list.grid,headers,'广汽本田9月区域特色售后服务活动顾客','广汽本田9月区域特色售后服务活动顾客'+(new Date().getTime())+'.xlsx');
            // location.href = list.baseUrl + attr.ctrlName + '/exportCustomerList?'+ (new Date().getTime()) + '&' + Ext.urlEncode(list.grid.store.baseParams);
        }
    }],
    columns:[
        {header:'ID',dataIndex:'customer_id',filter:{}},
        {header:'openid',dataIndex:'openid',width:200,filter:{}},
        {header:'活动',dataIndex:'h5_type',sort:true,filter:{xtype:'combofield',options:[['','全部']].concat(attr.type_arr)}
            ,renderer:function(val,m,r) {
                try {
                    val = JSON.parse(val);
                    var arr = [];
                    Ext.each(val,function(el) {
                        arr.push(ZM.id2name(el,attr.type_arr));
                    });
                    return arr.join(',');
                } catch(e) {
                    return '';
                }
            return ZM.id2name(val,attr.type_arr);
        }},
        {header:'奖品',dataIndex:'gift_type',sort:true,filter:{xtype:'combofield',options:[['','全部'],['1000','未抽奖'],['1001','未中奖'],['1002','已抽奖'],['-1','已中奖']].concat(attr.game_gift)}
            ,renderer:function(val,m,r) {
                if(val == 0) {
                    return r.json.lottery_times > 0 ? '未中奖' : '未抽奖';
                }
            return ZM.id2name(val,attr.game_gift);
        }},
        {header:'奖品状态',dataIndex:'gift_status',filter:{xtype:'combofield',options:[['','全部']].concat(attr.gift_status)},renderer:function(val,m,r) {
            if(r.json.gift_type == 0) {
                return '';
            }
            return ZM.id2name(val,attr.gift_status);
        }},
        {header:'卡券号',dataIndex:'gift_code',filter:{}},
        {header:'抽奖次数',dataIndex:'lottery_times',sort:true},
        {header:'姓名',dataIndex:'customer_name'},
        {header:'车架号',dataIndex:'customer_car_number',width:120},
        {header:'创建时间',dataIndex:'customer_time_create',width:140,filter:{xtype:'daterangefield'}},
        {header:'获奖时间',dataIndex:'customer_time_lottery',width:140,filter:{xtype:'daterangefield'}},
        {header:'状态',dataIndex:'customer_status',width:65,renderer:function(val) {
           return ZM.status(val == -2 ? '0' : 1);
        },filter:{
            xtype:'combofield',
            options:[['','全部'],['-2','禁用'],['0','激活']]
        }},
        {header:'初始化来源',dataIndex:'create_source',filter:{}},
        /*{header:'抽奖来源',dataIndex:'lottery_source',renderer:function(val) {
            try {
                val = JSON.parse(val);
                return val.join(',');
            } catch(e) {
                return '';
            }
        },filter:{}},
        {header:'核销来源',dataIndex:'validate_source',filter:{}},*/
        {header:'操作',renderer:function(v,p,r){
            var str = '';
            //str += Ext.rd('查看抽奖历史','fireDetail',r,attr.ctrlName+'/getLotteryHistoryList');
            if(r.json.customer_status == -2) {
                str += Ext.rd('激活','fireEnable',r,attr.ctrlName+'/enableCustomer');
            } else {
                str += Ext.rd('禁用','fireDisable',r,attr.ctrlName+'/disableCustomer');
            }
            return str;
        }}
    ]
});
/*
| -------------------------------------------------------------------
|  List Grid Action
| -------------------------------------------------------------------
*/
list.grid.fireDisable = function(r) {
    var r = r.json;
    Ext.Msg.confirm('确认?','确定要禁用顾客['+r.nickname+']?',function(btn) {
        if(btn != 'no') {
            ZM.ajax({
                url: list.baseUrl + attr.ctrlName+'/disableCustomer',
                params:{customer_id:r.customer_id},
                mask:list.grid,
                success:function(res){
                    ZM.bo.msg('success!',res.detail);
                    list.grid.store.reload();
                }
            });
        }
    });
}

list.grid.fireEnable = function(r) {
    var r = r.json;
    Ext.Msg.confirm('确认?','确定要激活顾客['+r.nickname+']?',function(btn) {
        if(btn != 'no') {
            ZM.ajax({
                url: list.baseUrl + attr.ctrlName+'/enableCustomer',
                params:{customer_id:r.customer_id},
                mask:list.grid,
                success:function(res){
                    ZM.bo.msg('success!',res.detail);
                    list.grid.store.reload();
                }
            });
        }
    });
}

<?php include dirname(__FILE__).'/common/layout.php'; ?>
list.grid.store.load();
<?php include dirname(__FILE__).'/common/footer.php'; ?>
